#!/usr/bin/env python
import os
import sys
import django

# 设置Django环境
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'backend'))
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'HuaXianGuan.settings')
django.setup()

from apps.flowers.models import FlowerCategory

def update_category_icons():
    """更新分类图标"""
    
    # 分类图标映射
    category_icons = {
        '玫瑰花': 'https://flower-1.oss-cn-shanghai.aliyuncs.com/icons/rose.png',
        '玫瑰花系列': 'https://flower-1.oss-cn-shanghai.aliyuncs.com/icons/rose.png',
        '康乃馨': 'https://flower-1.oss-cn-shanghai.aliyuncs.com/icons/carnation.png',
        '康乃馨系列': 'https://flower-1.oss-cn-shanghai.aliyuncs.com/icons/carnation.png',
        '百合花': 'https://flower-1.oss-cn-shanghai.aliyuncs.com/icons/lily.png',
        '百合花系列': 'https://flower-1.oss-cn-shanghai.aliyuncs.com/icons/lily.png',
        '向日葵': 'https://flower-1.oss-cn-shanghai.aliyuncs.com/icons/sunflower.png',
        '郁金香': 'https://flower-1.oss-cn-shanghai.aliyuncs.com/icons/tulip.png',
        '满天星': 'https://flower-1.oss-cn-shanghai.aliyuncs.com/icons/gypsophila.png'
    }
    
    print("更新分类图标...")
    
    categories = FlowerCategory.objects.all()
    updated_count = 0
    
    for category in categories:
        if category.name in category_icons:
            old_image = category.image
            category.image = category_icons[category.name]
            category.save()
            print(f"✓ 更新 {category.name}: {old_image} -> {category.image}")
            updated_count += 1
        else:
            print(f"⚠ 未找到图标: {category.name}")
    
    print(f"\n更新完成！共更新 {updated_count} 个分类图标")
    
    # 验证结果
    print("\n最终分类图标:")
    for category in FlowerCategory.objects.all():
        print(f"{category.name}: {category.image}")

if __name__ == '__main__':
    update_category_icons()